import { mapState } from "vuex"
// import store from './inedx.js'
import store from '@/mao-ui/store/index.js';

// 尝试将用户在根目录中的store/index.js的vuex的state变量，全部加载到全局变量中
let storeKey = [];
try{
	storeKey = store.state ? Object.keys(store.state) : [];
}catch(e){ }

module.exports = {
	created(){
		this.$mao.store = (name, value, forever=false) => {
			forever = forever ? true : false;
			this.$store.commit("setConfig", {
				name: name,
				value: value,
				forever: forever
			})
		},
		this.$mao.storeForever = (name, value) => {
			this.$store.commit("setConfig", {
				name: name,
				value: value,
				forever: true
			})
		},
		this.$mao.applyTheme = (theme) => {
			this.$store.commit("setConfig", {
				name: 'mao_theme',
				value: theme,
				forever: true
			})
		}
	},
	computed: {
		...mapState(storeKey)
	}
}